package com.xk.meeting.controller;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.*;
import java.io.IOException;

@WebServlet("/cancel")
public class CancelUserServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf8");
        Cookie[] cookies = request.getCookies();
        for (Cookie cookie : cookies){
            if(cookie.getName().equals("userKey")){
                cookie.setMaxAge(0);
                response.addCookie(cookie);
            }
            if(cookie.getName().equals("ssid")){
                cookie.setMaxAge(0);
                response.addCookie(cookie);
            }
        }
        HttpSession session = request.getSession();
        Object user = session.getAttribute("user");
        if(user != null){
            session.removeAttribute("user");
        }
        response.sendRedirect("login.jsp");
    }
}
